/*
 OLED屏驱动
*/

#include "sys.h"
#include "simi2c.h"
#include "delay.h"
#include "myoled.h"
//======================================================
// 128X64I液晶底层驱动[8X16]字体库
// 设计者: powerint
// 描  述: [8X16]西文字符的字模数据 (纵向取模,字节倒序)
// !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~
//======================================================

const unsigned char F8X16[]=
{
  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,// 0
  0x00,0x00,0x00,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x33,0x30,0x00,0x00,0x00,//!1
  0x00,0x10,0x0C,0x06,0x10,0x0C,0x06,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//"2
  0x40,0xC0,0x78,0x40,0xC0,0x78,0x40,0x00,0x04,0x3F,0x04,0x04,0x3F,0x04,0x04,0x00,//#3
  0x00,0x70,0x88,0xFC,0x08,0x30,0x00,0x00,0x00,0x18,0x20,0xFF,0x21,0x1E,0x00,0x00,//$4
  0xF0,0x08,0xF0,0x00,0xE0,0x18,0x00,0x00,0x00,0x21,0x1C,0x03,0x1E,0x21,0x1E,0x00,//%5
  0x00,0xF0,0x08,0x88,0x70,0x00,0x00,0x00,0x1E,0x21,0x23,0x24,0x19,0x27,0x21,0x10,//&6
  0x10,0x16,0x0E,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//'7
  0x00,0x00,0x00,0xE0,0x18,0x04,0x02,0x00,0x00,0x00,0x00,0x07,0x18,0x20,0x40,0x00,//(8
  0x00,0x02,0x04,0x18,0xE0,0x00,0x00,0x00,0x00,0x40,0x20,0x18,0x07,0x00,0x00,0x00,//)9
  0x40,0x40,0x80,0xF0,0x80,0x40,0x40,0x00,0x02,0x02,0x01,0x0F,0x01,0x02,0x02,0x00,//*10
  0x00,0x00,0x00,0xF0,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x1F,0x01,0x01,0x01,0x00,//+11
  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0xB0,0x70,0x00,0x00,0x00,0x00,0x00,//,12
  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x01,0x01,0x01,0x01,//-13
  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00,0x00,0x00,//.14
  0x00,0x00,0x00,0x00,0x80,0x60,0x18,0x04,0x00,0x60,0x18,0x06,0x01,0x00,0x00,0x00,///15
  0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x0F,0x10,0x20,0x20,0x10,0x0F,0x00,//016
  0x00,0x10,0x10,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//117
  0x00,0x70,0x08,0x08,0x08,0x88,0x70,0x00,0x00,0x30,0x28,0x24,0x22,0x21,0x30,0x00,//218
  0x00,0x30,0x08,0x88,0x88,0x48,0x30,0x00,0x00,0x18,0x20,0x20,0x20,0x11,0x0E,0x00,//319
  0x00,0x00,0xC0,0x20,0x10,0xF8,0x00,0x00,0x00,0x07,0x04,0x24,0x24,0x3F,0x24,0x00,//420
  0x00,0xF8,0x08,0x88,0x88,0x08,0x08,0x00,0x00,0x19,0x21,0x20,0x20,0x11,0x0E,0x00,//521
  0x00,0xE0,0x10,0x88,0x88,0x18,0x00,0x00,0x00,0x0F,0x11,0x20,0x20,0x11,0x0E,0x00,//622
  0x00,0x38,0x08,0x08,0xC8,0x38,0x08,0x00,0x00,0x00,0x00,0x3F,0x00,0x00,0x00,0x00,//723
  0x00,0x70,0x88,0x08,0x08,0x88,0x70,0x00,0x00,0x1C,0x22,0x21,0x21,0x22,0x1C,0x00,//824
  0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x00,0x31,0x22,0x22,0x11,0x0F,0x00,//925
  0x00,0x00,0x00,0xC0,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00,//:26
  0x00,0x00,0x00,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x60,0x00,0x00,0x00,0x00,//;27
  0x00,0x00,0x80,0x40,0x20,0x10,0x08,0x00,0x00,0x01,0x02,0x04,0x08,0x10,0x20,0x00,//<28
  0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x00,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x00,//=29
  0x00,0x08,0x10,0x20,0x40,0x80,0x00,0x00,0x00,0x20,0x10,0x08,0x04,0x02,0x01,0x00,//>30
  0x00,0x70,0x48,0x08,0x08,0x08,0xF0,0x00,0x00,0x00,0x00,0x30,0x36,0x01,0x00,0x00,//?31
  0xC0,0x30,0xC8,0x28,0xE8,0x10,0xE0,0x00,0x07,0x18,0x27,0x24,0x23,0x14,0x0B,0x00,//@32
  0x00,0x00,0xC0,0x38,0xE0,0x00,0x00,0x00,0x20,0x3C,0x23,0x02,0x02,0x27,0x38,0x20,//A33
  0x08,0xF8,0x88,0x88,0x88,0x70,0x00,0x00,0x20,0x3F,0x20,0x20,0x20,0x11,0x0E,0x00,//B34
  0xC0,0x30,0x08,0x08,0x08,0x08,0x38,0x00,0x07,0x18,0x20,0x20,0x20,0x10,0x08,0x00,//C35
  0x08,0xF8,0x08,0x08,0x08,0x10,0xE0,0x00,0x20,0x3F,0x20,0x20,0x20,0x10,0x0F,0x00,//D36
  0x08,0xF8,0x88,0x88,0xE8,0x08,0x10,0x00,0x20,0x3F,0x20,0x20,0x23,0x20,0x18,0x00,//E37
  0x08,0xF8,0x88,0x88,0xE8,0x08,0x10,0x00,0x20,0x3F,0x20,0x00,0x03,0x00,0x00,0x00,//F38
  0xC0,0x30,0x08,0x08,0x08,0x38,0x00,0x00,0x07,0x18,0x20,0x20,0x22,0x1E,0x02,0x00,//G39
  0x08,0xF8,0x08,0x00,0x00,0x08,0xF8,0x08,0x20,0x3F,0x21,0x01,0x01,0x21,0x3F,0x20,//H40
  0x00,0x08,0x08,0xF8,0x08,0x08,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//I41
  0x00,0x00,0x08,0x08,0xF8,0x08,0x08,0x00,0xC0,0x80,0x80,0x80,0x7F,0x00,0x00,0x00,//J42
  0x08,0xF8,0x88,0xC0,0x28,0x18,0x08,0x00,0x20,0x3F,0x20,0x01,0x26,0x38,0x20,0x00,//K43
  0x08,0xF8,0x08,0x00,0x00,0x00,0x00,0x00,0x20,0x3F,0x20,0x20,0x20,0x20,0x30,0x00,//L44
  0x08,0xF8,0xF8,0x00,0xF8,0xF8,0x08,0x00,0x20,0x3F,0x00,0x3F,0x00,0x3F,0x20,0x00,//M45
  0x08,0xF8,0x30,0xC0,0x00,0x08,0xF8,0x08,0x20,0x3F,0x20,0x00,0x07,0x18,0x3F,0x00,//N46
  0xE0,0x10,0x08,0x08,0x08,0x10,0xE0,0x00,0x0F,0x10,0x20,0x20,0x20,0x10,0x0F,0x00,//O47
  0x08,0xF8,0x08,0x08,0x08,0x08,0xF0,0x00,0x20,0x3F,0x21,0x01,0x01,0x01,0x00,0x00,//P48
  0xE0,0x10,0x08,0x08,0x08,0x10,0xE0,0x00,0x0F,0x18,0x24,0x24,0x38,0x50,0x4F,0x00,//Q49
  0x08,0xF8,0x88,0x88,0x88,0x88,0x70,0x00,0x20,0x3F,0x20,0x00,0x03,0x0C,0x30,0x20,//R50
  0x00,0x70,0x88,0x08,0x08,0x08,0x38,0x00,0x00,0x38,0x20,0x21,0x21,0x22,0x1C,0x00,//S51
  0x18,0x08,0x08,0xF8,0x08,0x08,0x18,0x00,0x00,0x00,0x20,0x3F,0x20,0x00,0x00,0x00,//T52
  0x08,0xF8,0x08,0x00,0x00,0x08,0xF8,0x08,0x00,0x1F,0x20,0x20,0x20,0x20,0x1F,0x00,//U53
  0x08,0x78,0x88,0x00,0x00,0xC8,0x38,0x08,0x00,0x00,0x07,0x38,0x0E,0x01,0x00,0x00,//V54
  0xF8,0x08,0x00,0xF8,0x00,0x08,0xF8,0x00,0x03,0x3C,0x07,0x00,0x07,0x3C,0x03,0x00,//W55
  0x08,0x18,0x68,0x80,0x80,0x68,0x18,0x08,0x20,0x30,0x2C,0x03,0x03,0x2C,0x30,0x20,//X56
  0x08,0x38,0xC8,0x00,0xC8,0x38,0x08,0x00,0x00,0x00,0x20,0x3F,0x20,0x00,0x00,0x00,//Y57
  0x10,0x08,0x08,0x08,0xC8,0x38,0x08,0x00,0x20,0x38,0x26,0x21,0x20,0x20,0x18,0x00,//Z58
  0x00,0x00,0x00,0xFE,0x02,0x02,0x02,0x00,0x00,0x00,0x00,0x7F,0x40,0x40,0x40,0x00,//[59
  0x00,0x0C,0x30,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x06,0x38,0xC0,0x00,//\60
  0x00,0x02,0x02,0x02,0xFE,0x00,0x00,0x00,0x00,0x40,0x40,0x40,0x7F,0x00,0x00,0x00,//]61
  0x00,0x00,0x04,0x02,0x02,0x02,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//^62
  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,//_63
  0x00,0x02,0x02,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//`64
  0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x19,0x24,0x22,0x22,0x22,0x3F,0x20,//a65
  0x08,0xF8,0x00,0x80,0x80,0x00,0x00,0x00,0x00,0x3F,0x11,0x20,0x20,0x11,0x0E,0x00,//b66
  0x00,0x00,0x00,0x80,0x80,0x80,0x00,0x00,0x00,0x0E,0x11,0x20,0x20,0x20,0x11,0x00,//c67
  0x00,0x00,0x00,0x80,0x80,0x88,0xF8,0x00,0x00,0x0E,0x11,0x20,0x20,0x10,0x3F,0x20,//d68
  0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x1F,0x22,0x22,0x22,0x22,0x13,0x00,//e69
  0x00,0x80,0x80,0xF0,0x88,0x88,0x88,0x18,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//f70
  0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x6B,0x94,0x94,0x94,0x93,0x60,0x00,//g71
  0x08,0xF8,0x00,0x80,0x80,0x80,0x00,0x00,0x20,0x3F,0x21,0x00,0x00,0x20,0x3F,0x20,//h72
  0x00,0x80,0x98,0x98,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//i73
  0x00,0x00,0x00,0x80,0x98,0x98,0x00,0x00,0x00,0xC0,0x80,0x80,0x80,0x7F,0x00,0x00,//j74
  0x08,0xF8,0x00,0x00,0x80,0x80,0x80,0x00,0x20,0x3F,0x24,0x02,0x2D,0x30,0x20,0x00,//k75
  0x00,0x08,0x08,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//l76
  0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x00,0x20,0x3F,0x20,0x00,0x3F,0x20,0x00,0x3F,//m77
  0x80,0x80,0x00,0x80,0x80,0x80,0x00,0x00,0x20,0x3F,0x21,0x00,0x00,0x20,0x3F,0x20,//n78
  0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x1F,0x20,0x20,0x20,0x20,0x1F,0x00,//o79
  0x80,0x80,0x00,0x80,0x80,0x00,0x00,0x00,0x80,0xFF,0xA1,0x20,0x20,0x11,0x0E,0x00,//p80
  0x00,0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x0E,0x11,0x20,0x20,0xA0,0xFF,0x80,//q81
  0x80,0x80,0x80,0x00,0x80,0x80,0x80,0x00,0x20,0x20,0x3F,0x21,0x20,0x00,0x01,0x00,//r82
  0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x33,0x24,0x24,0x24,0x24,0x19,0x00,//s83
  0x00,0x80,0x80,0xE0,0x80,0x80,0x00,0x00,0x00,0x00,0x00,0x1F,0x20,0x20,0x00,0x00,//t84
  0x80,0x80,0x00,0x00,0x00,0x80,0x80,0x00,0x00,0x1F,0x20,0x20,0x20,0x10,0x3F,0x20,//u85
  0x80,0x80,0x80,0x00,0x00,0x80,0x80,0x80,0x00,0x01,0x0E,0x30,0x08,0x06,0x01,0x00,//v86
  0x80,0x80,0x00,0x80,0x00,0x80,0x80,0x80,0x0F,0x30,0x0C,0x03,0x0C,0x30,0x0F,0x00,//w87
  0x00,0x80,0x80,0x00,0x80,0x80,0x80,0x00,0x00,0x20,0x31,0x2E,0x0E,0x31,0x20,0x00,//x88
  0x80,0x80,0x80,0x00,0x00,0x80,0x80,0x80,0x80,0x81,0x8E,0x70,0x18,0x06,0x01,0x00,//y89
  0x00,0x80,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x21,0x30,0x2C,0x22,0x21,0x30,0x00,//z90
  0x00,0x00,0x00,0x00,0x80,0x7C,0x02,0x02,0x00,0x00,0x00,0x00,0x00,0x3F,0x40,0x40,//{91
  0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,//|92
  0x00,0x02,0x02,0x7C,0x80,0x00,0x00,0x00,0x00,0x40,0x40,0x3F,0x00,0x00,0x00,0x00,//}93
  0x00,0x06,0x01,0x01,0x02,0x02,0x04,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//~94
};

//汉字字模数据

//温
uint8_t HZ1[]={
0x10,0x60,0x02,0x8C,0x00,0x00,0xFE,0x92,0x92,0x92,0x92,0x92,0xFE,0x00,0x00,0x00,
0x04,0x04,0x7E,0x01,0x40,0x7E,0x42,0x42,0x7E,0x42,0x7E,0x42,0x42,0x7E,0x40,0x00,
};

//度
uint8_t HZ2[]={
0x00,0x00,0xFC,0x24,0x24,0x24,0xFC,0x25,0x26,0x24,0xFC,0x24,0x24,0x24,0x04,0x00,
0x40,0x30,0x8F,0x80,0x84,0x4C,0x55,0x25,0x25,0x25,0x55,0x4C,0x80,0x80,0x80,0x00,
};

//湿
uint8_t HZ3[]={
0x10,0x60,0x02,0x8C,0x00,0xFE,0x92,0x92,0x92,0x92,0x92,0x92,0xFE,0x00,0x00,0x00,
0x04,0x04,0x7E,0x01,0x44,0x48,0x50,0x7F,0x40,0x40,0x7F,0x50,0x48,0x44,0x40,0x00,
};

//距
uint8_t HZ4[]={
0x00,0x3E,0x22,0xE2,0x22,0x3E,0x00,0xFE,0x22,0x22,0x22,0x22,0x22,0xE2,0x02,0x00,
0x20,0x3F,0x20,0x1F,0x11,0x11,0x00,0x7F,0x44,0x44,0x44,0x44,0x44,0x47,0x40,0x00,
};

//离
uint8_t HZ5[]={
0x04,0x04,0x04,0xF4,0x84,0xD4,0xA5,0xA6,0xA4,0xD4,0x84,0xF4,0x04,0x04,0x04,0x00,
0x00,0xFE,0x02,0x02,0x12,0x3A,0x16,0x13,0x12,0x1A,0x32,0x42,0x82,0x7E,0x00,0x00,
};

//光
uint8_t HZ6[]={
0x40,0x40,0x42,0x44,0x58,0xC0,0x40,0x7F,0x40,0xC0,0x50,0x48,0x46,0x40,0x40,0x00,
0x80,0x80,0x40,0x20,0x18,0x07,0x00,0x00,0x00,0x3F,0x40,0x40,0x40,0x40,0x78,0x00,
};

//照
uint8_t HZ7[]={
0x00,0xFE,0x42,0x42,0x42,0xFE,0x00,0x42,0xA2,0x9E,0x82,0xA2,0xC2,0xBE,0x00,0x00,
0x80,0x6F,0x08,0x08,0x28,0xCF,0x00,0x00,0x2F,0xC8,0x08,0x08,0x28,0xCF,0x00,0x00,
};

//酒
uint8_t HZ8[]={
0x20,0xC2,0x0C,0x80,0x02,0xF2,0x12,0x12,0xFE,0x12,0xFE,0x12,0x12,0xF2,0x02,0x00,
0x04,0x04,0x7E,0x01,0x00,0xFF,0x4A,0x49,0x48,0x48,0x48,0x49,0x49,0xFF,0x00,0x00,
};

//精
uint8_t HZ9[]={
0x44,0x58,0xC0,0xFF,0x50,0x4C,0x00,0x44,0x54,0x54,0x7F,0x54,0x54,0x54,0x44,0x00,
0x08,0x06,0x01,0xFF,0x01,0x06,0x00,0x00,0xFF,0x15,0x15,0x55,0x95,0x7F,0x00,0x00,
};

//浓
uint8_t HZ10[]={
0x10,0x60,0x02,0x8C,0x20,0x18,0x08,0xC8,0x38,0xCF,0x08,0x08,0x28,0x98,0x00,0x00,
0x04,0x04,0x7E,0x01,0x04,0x02,0x01,0xFF,0x40,0x21,0x06,0x0A,0x11,0x20,0x40,0x00,
};

//度
uint8_t HZ11[]={
0x00,0x00,0xFC,0x24,0x24,0x24,0xFC,0x25,0x26,0x24,0xFC,0x24,0x24,0x24,0x04,0x00,
0x40,0x30,0x8F,0x80,0x84,0x4C,0x55,0x25,0x25,0x25,0x55,0x4C,0x80,0x80,0x80,0x00,
};


//重
uint8_t HZ12[]={
0x10,0x10,0x14,0xD4,0x54,0x54,0x54,0xFC,0x52,0x52,0x52,0xD3,0x12,0x10,0x10,0x00,
0x40,0x40,0x50,0x57,0x55,0x55,0x55,0x7F,0x55,0x55,0x55,0x57,0x50,0x40,0x40,0x00,
};

//量
uint8_t HZ13[]={
0x20,0x20,0x20,0xBE,0xAA,0xAA,0xAA,0xAA,0xAA,0xAA,0xAA,0xBE,0x20,0x20,0x20,0x00,
0x00,0x80,0x80,0xAF,0xAA,0xAA,0xAA,0xFF,0xAA,0xAA,0xAA,0xAF,0x80,0x80,0x00,0x00,
};

//显示温度 和湿度
void OLed_ShowTemp(void)
{
	//第1行显示温度
	OLed_ShowChina(0,2,HZ1);
	OLed_ShowChina(16,2,HZ2);
	
	  //第2行显示湿度
	OLed_ShowChina(0,4,HZ3);
	OLed_ShowChina(16,4,HZ2);
}

//显示距离汉字
void OLed_ShowDist(void)
{
	//第2行显示距离
	OLed_ShowChina(16,2,HZ4);
	OLed_ShowChina(32,2,HZ5);
}

//显示光照汉字
void OLed_ShowLight(void)
{
	//第2行显示光照	
	OLed_ShowChina(0,0,HZ6);
	OLed_ShowChina(16,0,HZ7);
}

//显示酒精浓度汉字
void OLed_ShowAlcol(void)
{
	//第2行显示酒精浓度
	OLed_ShowChina(0,2,HZ8);
	OLed_ShowChina(16,2,HZ9);
	OLed_ShowChina(32,2,HZ10);
	OLed_ShowChina(48,2,HZ11);
}


//显示重量汉字
void OLed_ShowWeight(void)
{
	//第2行显示重量
	OLed_ShowChina(16,2,HZ12);
	OLed_ShowChina(32,2,HZ13);
}



/*
 写OLED命令寄存器的函数
*/
void WriteOLedCmd(uint8_t cmd)
{
	uint8_t CtrWord = 0x00;
	
	IIC_Start();
	
	IIC_Send_Byte(OLED_SLAVE_ADDR_WR); 	//发送从设备地址
	IIC_Wait_Ack();
	
	IIC_Send_Byte(CtrWord); //发送命令控制字
	IIC_Wait_Ack();
	
	IIC_Send_Byte(cmd);
	IIC_Wait_Ack();
	
	IIC_Stop();
}

/*
  写OLED数据的函数
*/

void WriteOLedData(uint8_t data)
{

	uint8_t CtrWord = 0x00;
	
	CtrWord |= (0x1<<6);  //表示发送的是数据	
	
	IIC_Start();

	IIC_Send_Byte(OLED_SLAVE_ADDR_WR); 	//发送从设备地址
	IIC_Wait_Ack();
	
	IIC_Send_Byte(CtrWord); //发送命令控制字
	IIC_Wait_Ack();
	
	IIC_Send_Byte(data);
	IIC_Wait_Ack();
	
	IIC_Stop();
}




/*
 设置显示位置
 y--> page address页地址  ,相当于 行 (0 ~ 7)       1 100
 x --> 列地址 (0 ~ 127)
*/
void OLed_SetPos(unsigned char x, unsigned char y)
{ 
	WriteOLedCmd((0xb0+y));  //设置行地址，设置页号
	WriteOLedCmd(((x&0xf0)>>4)|0x10);  //设置列地址高位
	WriteOLedCmd((x&0x0f)|0x00);   //设置列地址的低位
}


#define X_WIDTH   128

/*
 填充显示数据缓冲区
*/
void OLed_Fill(unsigned char bmp_data)
{
	unsigned char y,x;

	for(y=0;y<8;y++)  
	{
		  //设置PAGE地址
			WriteOLedCmd(0xb0+y); 
		  //设置列地址
			WriteOLedCmd(0x00);  
			WriteOLedCmd(0x10);
			
			for(x=0;x<X_WIDTH;x++)
			{
				WriteOLedData(bmp_data);  
			}
	}
	
}

void InitOLed(void)
{
	  //给OLED发送命令 初始化OLED
		WriteOLedCmd(0xAE);//--turn off oled panel
		WriteOLedCmd(0x00);//---set low column address
		WriteOLedCmd(0x10);//---set high column address
		WriteOLedCmd(0x40);//--set start line address  Set Mapping RAM Display Start Line (0x00~0x3F)
		WriteOLedCmd(0x81);//--set contrast control register
		WriteOLedCmd(0xCF); // Set SEG Output Current Brightness
		WriteOLedCmd(0xA1);//--Set SEG/Column Mapping     0xa0???? 0xa1??
		WriteOLedCmd(0xC8);//Set COM/Row Scan Direction   0xc0???? 0xc8??
		WriteOLedCmd(0xA6);//--set normal display
		WriteOLedCmd(0xA8);//--set multiplex ratio(1 to 64)
		WriteOLedCmd(0x3f);//--1/64 duty
		WriteOLedCmd(0xD3);//-set display offset	Shift Mapping RAM Counter (0x00~0x3F)
		WriteOLedCmd(0x00);//-not offset
		WriteOLedCmd(0xd5);//--set display clock divide ratio/oscillator frequency
		WriteOLedCmd(0x80);//--set divide ratio, Set Clock as 100 Frames/Sec
		WriteOLedCmd(0xD9);//--set pre-charge period
		WriteOLedCmd(0xF1);//Set Pre-Charge as 15 Clocks & Discharge as 1 Clock
		WriteOLedCmd(0xDA);//--set com pins hardware configuration
		WriteOLedCmd(0x12);
		WriteOLedCmd(0xDB);//--set vcomh
		WriteOLedCmd(0x40);//Set VCOM Deselect Level
		WriteOLedCmd(0x20);//-Set Page Addressing Mode (0x00/0x01/0x02)
		WriteOLedCmd(0x02);//
		WriteOLedCmd(0x8D);//--set Charge Pump enable/disable
		WriteOLedCmd(0x14);//--set(0x10) disable
		WriteOLedCmd(0xA4);// Disable Entire Display On (0xa4/0xa5)
		WriteOLedCmd(0xA6);// Disable Inverse Display On (0xa6/a7) 
		WriteOLedCmd(0xAF);//--turn on oled panel
		
		WriteOLedCmd(0xAF); /*display ON*/ 
		
		OLed_Fill(0x00);
	
}

void offInitOLed(void)
{
	  //给OLED发送命令 初始化OLED
		WriteOLedCmd(0xAE);//--turn off oled panel
		WriteOLedCmd(0x00);//---set low column address
		WriteOLedCmd(0x10);//---set high column address
		WriteOLedCmd(0x40);//--set start line address  Set Mapping RAM Display Start Line (0x00~0x3F)
		WriteOLedCmd(0x81);//--set contrast control register
		WriteOLedCmd(0xCF); // Set SEG Output Current Brightness
		WriteOLedCmd(0xA1);//--Set SEG/Column Mapping     0xa0???? 0xa1??
		WriteOLedCmd(0xC8);//Set COM/Row Scan Direction   0xc0???? 0xc8??
		WriteOLedCmd(0xA6);//--set normal display
		WriteOLedCmd(0xA8);//--set multiplex ratio(1 to 64)
		WriteOLedCmd(0x3f);//--1/64 duty
		WriteOLedCmd(0xD3);//-set display offset	Shift Mapping RAM Counter (0x00~0x3F)
		WriteOLedCmd(0x00);//-not offset
		WriteOLedCmd(0xd5);//--set display clock divide ratio/oscillator frequency
		WriteOLedCmd(0x80);//--set divide ratio, Set Clock as 100 Frames/Sec
		WriteOLedCmd(0xD9);//--set pre-charge period
		WriteOLedCmd(0xF1);//Set Pre-Charge as 15 Clocks & Discharge as 1 Clock
		WriteOLedCmd(0xDA);//--set com pins hardware configuration
		WriteOLedCmd(0x12);
		WriteOLedCmd(0xDB);//--set vcomh
		WriteOLedCmd(0x40);//Set VCOM Deselect Level
		WriteOLedCmd(0x20);//-Set Page Addressing Mode (0x00/0x01/0x02)
		WriteOLedCmd(0x02);//
		WriteOLedCmd(0x8D);//--set Charge Pump enable/disable
		WriteOLedCmd(0x14);//--set(0x10) disable
		WriteOLedCmd(0xA4);// Disable Entire Display On (0xa4/0xa5)
		WriteOLedCmd(0xA6);// Disable Inverse Display On (0xa6/a7) 
		WriteOLedCmd(0xAF);//--turn on oled panel
		
	
}

uint8_t fbuf1[]={0x00,0x00,0xF0,0x10,0x10,0x10,0x10,0xFF,0x10,0x10,0x10,0x10,0xF0,0x00,0x00,0x00};
uint8_t fbuf2[]={0x00,0x00,0x0F,0x04,0x04,0x04,0x04,0xFF,0x04,0x04,0x04,0x04,0x0F,0x00,0x00,0x00};/*中*/

uint8_t fbuf3[]={0x00,0xFE,0x02,0x12,0x92,0x92,0x92,0xF2,0x92,0x92,0x92,0x12,0x02,0xFE,0x00,0x00};
uint8_t fbuf4[]={0x00,0xFF,0x40,0x48,0x48,0x48,0x48,0x4F,0x48,0x4A,0x4C,0x48,0x40,0xFF,0x00,0x00};/*国*/

/*
功能：在指定位置显示指定ASCII码对应字符串 
@x: 显示的行号(页号0~7)
@y:显示的列号(列号0~127)
@str: 要显示的ascii的字符串
*/
void OLed_ShowASCII(uint8_t x, uint8_t y,char *str)
{
		uint8_t i = 0;
	
		char *pstr = str;
	
		while(*pstr)
		{
				OLed_SetPos(x,y);
				for(i=0;i<8;i++)  
				{	
					WriteOLedData(F8X16[((*pstr)-32)*16+i]);
				}
				
				OLed_SetPos(x,y+1);
				for(i=0;i<8;i++)  
				{	
					WriteOLedData(F8X16[((*pstr)-32)*16+8+i]);
				}
				
				pstr++;
				
				x +=8;
		}
		
}



/*
 功能: 在指定位置显示一个汉字, 显示下一个汉字时，X每次递增16
 Y递增 2  字模数据 buf
*/
void OLed_ShowChina(uint8_t x,uint8_t y,uint8_t *buf)
{
		uint8_t i = 0;
	
		OLed_SetPos(x,y);
		for(i=0;i<16;i++)  
		{	
			WriteOLedData(buf[i]);
		}
		
		OLed_SetPos(x,(y+1));
		for(i=0;i<16;i++)  
		{	
			WriteOLedData(buf[i+16]);
		}
}


/*
 在 x,y 位置显示 

*/
void OLed_ShowTest(unsigned char x,unsigned char y)
{
		uint8_t i = 0;
	
		OLed_SetPos(x,y);
		for(i=0;i<16;i++)  
		{	
			WriteOLedData(fbuf1[i]);
		}
		
		OLed_SetPos(x,(y+1));
		for(i=0;i<16;i++)  
		{	
			WriteOLedData(fbuf2[i]);
		}
		
		OLed_SetPos((x+16),y);
		for(i=0;i<16;i++)  
		{	
			WriteOLedData(fbuf3[i]);
		}
		
		OLed_SetPos((x+16),(y+1));
		for(i=0;i<16;i++)  
		{	
			WriteOLedData(fbuf4[i]);
		}
		
	
}

void SSD1306_DrawBMP(unsigned char x0, unsigned char y0,unsigned char x1,unsigned char y1,unsigned char BMP[])
{
	unsigned int j=0;
	unsigned char x,y;
	if(y1%8 == 0) y = y1/8;
	else y = y1/8+1;
	for(y=y0;y<y1;y++)
	{
		OLed_SetPos(x0,y);
		for(x=x0;x<x1;x++)
		{
			WriteOLedData(BMP[j++]);
		}
	}
}